package leetcode.sword;

import datastruct.list.ListNode;

public class Solution18 {

    public ListNode deleteNode(ListNode head, int val) {
        ListNode virHead = new ListNode();
        virHead.next = head;
        ListNode pre = virHead, cur = head;
        while (cur!=null&&cur.val!=val){
            cur = cur.next;
            pre = pre.next;
        }
        //删除
        if(cur!=null) pre.next = cur.next;
        return virHead.next;
    }
}
